home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Unix / satan-1.1.1 / perl / drop_fact.pl < prev    next >
Text File  |  1995-04-10  |  1KB  |  73 lines

  1. #
  2. # Usage: $code = &drop_fact()
  3. # Applies the rules in $drop_fact_files to the global $target..$text 
  4. # variables. The result value is nonzero if the record should be ignored.
  5. # Standalone usage: perl drop_fact.pl [satan_record_files...]
  6.  
  7. $drop_fact_files = "rules/drop";
  8.  
  9. sub build_drop_fact{
  10.     local($files) = @_;
  11.     local($code);
  12.  
  13.     $code = "sub drop_fact {\n";
  14.  
  15.     foreach $file (split(/\s+/, $files)) {
  16.     open(RULES, $file) || die "cannot open $file: $!";
  17.     while (<RULES>) {
  18.         chop;
  19.         while (/\\$/) {
  20.         chop;
  21.         $_ .= <RULES>;
  22.         chop;
  23.         }
  24.         s/#.*$//;
  25.         next if /^\s*$/;
  26.         s/@/\\@/g;
  27.         $code .= "\tif ($_) {\n\t\treturn 1;\n\t}\n";
  28.     }
  29.     close(RULES);
  30.     }
  31.     $code .= "\treturn 0;\n}\n";
  32.     return $code;
  33. }
  34.  
  35. #
  36. # Some scaffolding for stand-alone operation
  37. #
  38. if ($running_under_satan) {
  39.     eval &build_drop_fact($drop_fact_files);
  40.     die "error in $drop_fact_files: $@" if $@;
  41. } else {
  42.     $running_under_satan = -1;
  43.  
  44.     require 'perl/misc.pl';
  45.  
  46.     #
  47.     # Build satan rules and include them into the running code.
  48.     #
  49.     $code = &build_drop_fact($drop_fact_files);
  50.     print "Code generated from $drop_fact_files file:\n\n";
  51.     print $code;
  52.     eval $code;
  53.     die "error in $drop_fact_files: $@" if $@;
  54.  
  55.     #
  56.     # Apply rules.
  57.     #
  58.     print "\nApplying rules to all SATAN records...\n";
  59.     while (<>) {
  60.     chop;
  61.     if (&satan_split($_)) {
  62.         warn "Ill-formed fact: $_\n";
  63.     } elsif (&drop_fact()) {
  64.         print "Dropped: $_\n";
  65.     }
  66.     }
  67. }
  68.  
  69. 1;
  70.